package com.huatai.common.config;

import com.huatai.common.interceptor.UserAuthContextInterceptor;
import com.huatai.common.properties.SkipUrlProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @program: ganghua
 * @description: 过滤器添加
 * @author: songxiude
 * @create: 2024-09-25 10:01
 **/
@Configuration
public class UserAuthConfig implements WebMvcConfigurer {
	@Value("${huatai.bmd.skip-url}")
	private String urls;
	@Autowired
	private SkipUrlProperties skipUrlProperties;
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		String[] excludeUrls = urls.split(",");

//		String[]  skipUrl= skipUrlProperties.getSkipUrl().toArray(new String[skipUrlProperties.getSkipUrl().size()]);
		registry.addInterceptor(getUserAuthContextInterceptor())
			.addPathPatterns("/**")
			.excludePathPatterns(excludeUrls)
			.order(-10);
	}

	public UserAuthContextInterceptor getUserAuthContextInterceptor(){
		return new UserAuthContextInterceptor();
	}
}
